package com.matt.repository.nursery;

import com.matt.domain.nursery.NurseryInstructionRecord;
import com.matt.foundation.vo.nursery.InstructionRecordVo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * *******************************
 * Created by lch.
 * form com.matt
 * on 2018/11/26
 * *******************************
 */

public interface NurseryInstrationRecordRepository  extends JpaRepository<NurseryInstructionRecord, String>, JpaSpecificationExecutor<NurseryInstructionRecord> {

    List<NurseryInstructionRecord> findAllByTargetObjectId(String targetObjectId);
    
//    List<InstructionRecordVo> findByTargetObjectId(Integer month,Integer day,Integer orderyMoney);
    
    @Query(value="select a.Order_Money as orderMoney,a.From_Time as fromTime,a.To_Time as toTime,a.Month as month,a.Day as day,b.Title as title,b.Media as media from m_baby_defaulthandbook a left join m_test_store b on a.TestStore_ID=b.ID where a.Month=?1 and a.Day=?2 and a.Is_Deleted = 0 and b.Title is not null group by a.From_Time order by a.From_Time asc",nativeQuery=true)
    List<Object[]> findInstructionRecordVoByMonthAndDay(@Param("Month") Integer Month,@Param("Type") Integer Type);
    
    @Query(value="select b.Month as month,b.Title as title,b.Media as media,b.Type as type from  m_test_store b  where b.Month=?1 and b.Type=?2 and b.IsDelete = 0 and b.Title is not null order by b.Month asc",nativeQuery=true)
    List<Object[]> findInstructionResourceRecordVoByMonthAndType(@Param("Month") Integer Month,@Param("Type") Integer type);
}
